
#include "my_net.h"
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>

void PrintSockaddr(struct sockaddr *value, socklen_t len) {

  switch (len) {
  case sizeof(struct sockaddr_in):{
    struct sockaddr_in * ptr = (struct sockaddr_in*)value;
    if(!ptr){

      break;
    }
    char buffer[32];
    inet_ntop(ptr->sin_family, &ptr->sin_addr, buffer, sizeof(buffer));
    printf("port = %d and addr = %s\n", ntohs(ptr->sin_port), buffer);
    break;
  }
  case sizeof(struct sockaddr_in6):{
    struct sockaddr_in6 * ptr = (struct sockaddr_in6 *)value;
    if (!ptr){

      break;
    }
    char buffer[128];
    inet_ntop(ptr->sin6_family, &ptr->sin6_addr, buffer, sizeof(buffer));
    printf("port = %d and addr = %s\n", ntohs(ptr->sin6_port),buffer);
    break;
  }
  }
}
